<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.2/echarts.min.js"></script>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
            crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '所有男女人数各自的总和'
        },
        tooltip: {},
        xAxis: {
            data: ["male", "female"]
        },
        yAxis: {},
        series: [{
            name: '人数',
            type: 'bar',
            data: [0, 0]
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    function updateData() {
        fetch('dd')
            .then(resp => resp.json())
            .then(data => {
                myChart.setOption({
                    series: [{
                        data: [data.male, data.female]
                    }]
                });
            })
            .catch(console.error);
    }

    setInterval(updateData, 2000); // 每2秒更新一次数据
</script>
</body>
</html>
